<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<form>
    <div id="toolbar" class="btn-group">
        <button  class="add-btn layui-btn layui-btn-normal layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
            <i class="fa fa-plus" aria-hidden="true"></i> 新增渠道
        </button>
        <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
            <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
        </button>
    </div>
</form>
<div class="wrapper wrapper-content">
    <!-- START 数据表格 -->
    <table id="channelTable"
           data-toolbar="#toolbar"
           data-side-pagination="server"
           data-pagination="true"
           data-resizable="true"
           data-url="/sea/product/channel/findByCnd.do"
           data-page-size="15"
           class="table table-striped table-hover"
    >
    </table>
    <!-- END 数据表格 -->
</div>

<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <input type="hidden" id="categoryParentId" name="categoryParentId">
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">渠道平台</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="channelName" name="channelName" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer'}){}%>
<script>
    var $channelTable = $('#channelTable');
    $(function(){


        //START 表格配置
        $channelTable.bootstrapTable({
            pageSize:10,
            columns: [
                {
                    title: '渠道',
                    field: 'channelName',
                    align: 'center',
                    valign: 'middle'
                },{
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                //删除数据字典详情信息
                $('.del-btn').on('click',function(){
                    var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-name');
                    //删除提示
                    layer.confirm('确定要删除当前数据？<br>['+delname+']', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/product/channel/delete.do',{id: delid},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $channelTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });

            }
        });
        //END 表格配置
    });

    // 操作菜单
    function optFormatter(value,row){
        var content = '';
        content += '&nbsp;<a class="del-btn btn btn-xs btn-danger" data-val-name="'+row.channelName+'" data-val="'+row.id+'" title="删除"><i class="fa fa-trash-o"></i> 删除 </a>';
        return content;
    }

    $('.add-btn').on('click',function(){
        layer.open({
            type:1,
            title:'添加渠道平台',
            area:['600px','250px'],
            skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
            shadeClose:false,
            resize: false,
            scrollbar: false,
            maxmin: false,//出现最大化按钮
            content:$('#layer_window')
        })
    });


    //提交表单
    $('.save-btn').on('click',function(){
        layer.confirm('确定要新增当前渠道？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            var channelName=$("#channelName").val();
            if(channelName==''){
                parent.layer.msg('请填写渠道平台名称！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            layer.closeAll();
            var index=layer.load();
            $.post('/sea/product/channel/save.do',{channelName:channelName},function(data){
                if( data.ok ){
                    $channelTable.bootstrapTable('refresh');
                    layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);

                }else{
                    layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);

                }
            });
        });
    });
    $(".export-btn").click(function () {
        window.location.href='/sea/product/channel/export.do?'+$('#search-form').serialize();
    });
</script>
</body>
</html>
